<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Cloudlead Dashboard</title>
<link rel="stylesheet" href="../styles/metro-green/easyui.css">
<link rel="stylesheet" href="../styles/icon.css">
<link rel="stylesheet" href="../styles/style.css" />
<link rel="stylesheet" href="../styles/jsonwidget.css" />
<link rel="stylesheet" href="../styles/codemirror.css" />
<link rel="stylesheet" href="../styles/eclipse.css" />
<link rel="stylesheet" href="../styles/api.css" />

<script type="text/javascript" src="../scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="../scripts/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../scripts/i18n/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../scripts/json2.js"></script>
<script type="text/javascript" src="../scripts/form2json.js"></script>
<script type="text/javascript" src="../scripts/helpJSONView.js"></script>
<script type="text/javascript" src="../scripts/codemirror/codemirror.js"></script>
<script type="text/javascript" src="../scripts/codemirror/active-line.js"></script>
<script type="text/javascript"
	src="../scripts/codemirror/mark-selection.js"></script>
<script type="text/javascript" src="../scripts/codemirror/json.js"></script>
<script type="text/javascript" src="../scripts/jsonedit.js"></script>
<script type="text/javascript" src="../scripts/api.js"></script>
<script type="text/javascript">
	$().ready(
			function() {
				$.extend($.fn.validatebox.defaults.rules, {
					minLength : {
						validator : function(value, param) {
							return value.length >= param[0];
						},
						message : '请最少输入{0}个字符'
					}
				});
				$.extend($.fn.validatebox.defaults.rules, {
					maxLength : {
						validator : function(value, param) {
							return value.length <= param[0];
						},
						message : '请输入最多{0}个字符'
					}
				});
				$.extend($.fn.validatebox.defaults.rules, {
					pattern : {
						validator : function(value, param) {
							return param[0].test(value);
						},
						message : '请输入一个符合 {0} 格式的字符串'
					}
				});
				$.extend($.fn.validatebox.defaults.rules, {
					number : {
						validator : function(value, param) {
							return /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/
									.test(value);
						},
						message : '请输入合法的数字'
					}
				});
				$.extend($.fn.validatebox.defaults.rules, {
					date : {
						validator : function(value, param) {
							return /^\d{4}\-\d{2}\-\d{2}$/.test(value);
						},
						message : '请输入合法的日期'
					}
				});
				$.extend($.fn.validatebox.defaults.rules, {
					datetime : {
						validator : function(value, param) {
							return /^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}(:\d{2})?$/
									.test(value);
						},
						message : '请输入合法的日期时间'
					}
				});

				$('#es_window').window('close');

				$.get("/resources/dashboard", function(data) {
					$.each(data, function(index, value) {
						var serverListDiv = document.createElement("div");
						$(serverListDiv).addClass("historyLink");
						var icon = document.createElement("span");
						$(icon).css("padding", "5px 5px 5px 20px");
						$(icon).addClass("icon-application-link");
						$(serverListDiv).append(icon);
						var serverListLink = document.createElement("a");
						$(serverListLink).text(value.workerName + "(" + value.workerIp+":"+value.workerPort+")");
						$(serverListDiv).append(serverListLink);
						$("#api_server_listdiv").append(serverListDiv);

						$(serverListDiv).hover(function() {
							$(this).addClass("linkHover");
						}, function() {
							$(this).removeClass("linkHover");
						});

						$(serverListLink).click(function() {
							$(serverListDiv).siblings().removeClass("linkSelected");
							$(serverListDiv).addClass("linkSelected");

							new api("http://"+value.workerIp+":"+value.workerPort+"/");
						});
					});
				});

//				new api("http://localhost:8190/");

				$("#index_btn").click(function(){
					location.href="/pages/api.html";
				});
			});
</script>
</head>
<body class="easyui-layout">
	<div data-options="region:'north',border:false"
		style="background: #f1f3e9">
		<div id="top">
			<div id="topbar">
				<ul class="topmenu">
					<li class="page_item page-item-12"><a href="/pages/api.html">Cloudlead Dashboard</a></li>
				</ul>
			</div>
		</div>
		<div id="page">
			<div id="header">
				<div id="blogname">
					<h2>
						<a href="/pages/api.html">Cloudlead Dashboard</a>
					</h2>
					<p>&nbsp;&nbsp;API列表</p>
				</div>
			</div>
		</div>
	</div>

	<div data-options="region:'west',split:true,title:'动作'"
		style="width: 320px; overflow: hidden;">
		<div style="background-color: #F1F3E9">
			<a id="index_btn" href="javascript:void(0)"
				class="easyui-linkbutton"
				data-options="toggle:true,plain:true,group:'g1',iconCls:'icon-application-home'">首页</a>
			<a id="api_collapse_all_btn" href="javascript:void(0)"
				class="easyui-linkbutton"
				data-options="toggle:true,plain:true,group:'g1',iconCls:'icon-application-osx'">合并</a>
			<a id="api_expand_all_btn" href="javascript:void(0)"
				class="easyui-linkbutton"
				data-options="toggle:true,plain:true,group:'g1',iconCls:'icon-application-osx-cascade'">展开</a>
			<a id="api_show_history_btn" href="javascript:void(0)"
				class="easyui-linkbutton"
				data-options="toggle:true,plain:true,group:'g1',iconCls:'icon-database-save'">历史</a>
			<a id="api_show_tree_btn" href="javascript:void(0)"
				class="easyui-linkbutton"
				data-options="toggle:true,plain:true,group:'g1',iconCls:'icon-back'"
				style="display: none;">返回</a>
			<a id="api_execute_btn"
				href="javascript:void(0)" class="easyui-linkbutton"
				data-options="toggle:true,plain:true,group:'g1',iconCls:'icon-application-go'" style="display: none;">执行</a>
			<a id="api_module_enable_btn"
				href="javascript:void(0)" class="easyui-linkbutton"
				data-options="toggle:true,plain:true,group:'g1',iconCls:'icon-ok'" style="display: none;">启用</a>
			<a id="api_module_disable_btn"
				href="javascript:void(0)" class="easyui-linkbutton"
				data-options="toggle:true,plain:true,group:'g1',iconCls:'icon-no'" style="display: none;">禁用</a>
		</div>
		<div id="api_server_listdiv"
			 style="overflow: auto; height: 95%; "></div>
		<div id="api_action_treediv" style="overflow: auto; height: 95%;display: none;"></div>
		<div id="api_action_historydiv"
			style="overflow: auto; height: 95%; display: none;"></div>
	</div>
	<div data-options="region:'center',title:'请求'" style="padding: 10px;">
		<div id="api_req_warningdiv"></div>
		<div id="api_reqdiv" style="height: 472px;">
			<div title="表单">
				<form method='POST' id="api_req_form">
					<div id="api_req_formdiv" style="text-background: white;"></div>
				</form>
			</div>
			<div title="源码">
				<form method='POST' id="api_req_sourcetextform">
					<textarea id="api_req_sourcetextarea" rows="30" cols="80"
						name="sourcearea">
					</textarea>
				</form>
			</div>
			<!-- <div title="schema表单">
				<div id="api_req_schemaformdiv" style="text-background: white">
				</div>
			</div> -->
			<div title="定义">
				<div id="api_req_schemaformdiv" style="display: none;"></div>
				<textarea id="api_req_schematextarea" style="display: none"
					rows="30" cols="80"></textarea>
				<div id="api_req_schemacontent" style="padding: 10px;"></div>
			</div>
		</div>

		<textarea id="api_req_schemaschematextarea" style="display: none"
			rows="30" cols="80" name="sourcearea">
{
	"label": "Schema",
	"type": "map",
	"id": "schemanode",
	"desc": "A schema describing a particular JSON format",
	"required": true,
	"mapping": {
		"type": {
			"type": "str",
			"required": true,
			"label": "Type (type)",
			"desc": "The datatype of the property (e.g. number, boolean, etc), used for determining the semantics of the variable described",
			"enum": ["any",
			"str",
			"int",
			"number",
			"bool",
			"seq",
			"map",
			"idref"],
			"desc_enum": {
				"any": "Any datatype allowed",
				"str": "String",
				"int": "Integer number",
				"number": "Any number (floating point or integer)",
				"bool": "Boolean (true or false) value",
				"seq": "Nested sequence of items ('array' in many languages).  You must also have a 'sequence' property which is itself a sequence containing a single schema definition",
				"map": "Nested mapping of key/value pairs (a.k.a. 'properties').  You must also have a 'mapping' property which is itself a sequence containing a single schema definition"
			}
		},
		"label": {
			"type": "str",
			"label": "Title (label)",
			"desc": "A user-friendly label for the property"
		},
		"id": {
			"type": "str",
			"label": "Identifier (id)",
			"desc": "An identifier used to reference this property using the 'idref' property"
		},
		"desc": {
			"type": "str",
			"label": "Description (desc)",
			"desc": "A description for use in documentation and context help"
		},
		"user_key": {
			"type": "str",
			"label": "User named key (user_key)",
			"desc": "Key for properties named by the user.  Use only when type=map, and ensure there's a corresponding property schema in the mapping"
		},
		"idref": {
			"type": "str",
			"label": "Identifier reference (idref)",
			"desc": "Reference to a schema segment with the given 'id' property.  The 'type' attribute must be set to 'idref'."
		},
		"enum": {
			"type": "seq",
			"sequence": [{
				"type": "any"
			}],
			"label": "Enumeration (enum)",
			"desc": "Enumerated sequence of valid values for this property."
		},
		"desc_enum": {
			"type": "map",
			"user_key": "enumdesc",
			"mapping": {
				"enumdesc": {
					"label": "Description for enum value",
					"type": "str",
					"desc": "A mapping containing a description for each possible value listed in the enumeration (enum) property.  Used for documentation and context help."
				}
			}
		},
		"format": {
			"type": "str",
			"label": "Strig format",
			"desc": "Format for this property.",
			"enum": ["date",
			"datetime"]
		},
		"required": {
			"type": "bool",
			"label": "Required property? (required)",
			"desc": "If 'true', then this property must always be present"
		},
		"validators": {
			"type": "seq",
			"label": "Property validators.",
			"desc": "",
			"sequence": [{
				"type": "map",
				"user_key": "validatorItem",
				"mapping": {
					"validatorItem": {
						"type": "any"
					}
				}
			}]
		},
		"mapping": {
			"type": "map",
			"label": "Mapping (mapping)",
			"desc": "A mapping containing schema segments describing each property in the mapping.  The 'type' property must be set to 'map' to use this property.",
			"user_key": "schemachild",
			"mapping": {
				"schemachild": {
					"type": "idref",
					"idref": "schemanode"
				}
			}
		},
		"sequence": {
			"type": "seq",
			"label": "Sequence (sequence)",
			"desc": "A sequence containing a single schema segment",
			"sequence": [{
				"type": "idref",
				"idref": "schemanode"
			}]
		}
	}
}
			</textarea>
		</div>
		<div data-options="region:'east',split:true,title:'响应'"
			style="width: 300px; padding: 10px;">
			<div id="api_respdiv" style="height: 472px">
				<div id="api_resp_headerdiv" title="响应头" style="padding: 10px;">
				</div>
				<div id="api_resp_contentdiv" title="响应体"
					style="height: 100%; padding: 10px;"></div>
			</div>
		</div>
		<div data-options="region:'south',border:false">
			<div id="footer">
				<div>&nbsp;</div>
				© 2015-2030 www.cloudlead-partners.com
				<div>&nbsp;</div>
			</div>
		</div>
	</body>
</html>